<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>调色板</title>
    <style>
        *{
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        .container{
            width: 400px;
            min-height: 300px;
            margin: 50px auto;
            border:solid 1px #ddd;
        }

        .color-show{
            height: 250px;
            background: #aef;
        }
        .control{
            padding: 20px;
        }
    </style>
</head>
<body>
    <div id="root">
        
    </div>
    <script src="../js/react.development.js"></script>
    <script src="../js/react-dom.development.js"></script>
    <script src="../js/babel.min.js"></script>

    <script type="text/babel">
        class App extends React.Component {
            state = {
                r: 25,
                g: 200,
                b: 150,
            }

            render(){
                //获取 r g b 的值
                let {r,g,b} = this.state;
                return <div className="container">
                    <div className="color-show" style={{background: `rgb(${r},${g},${b})`}} ></div>
                    <hr />
                    <div className="control">
                        R: <input type="range" min="0" max="255"  value={this.state.r}  onChange={this.saveR}  /><br/>
                        G: <input type="range" min="0" max="255" value={this.state.g} onChange={this.saveG}/><br/>
                        B: <input type="range" min="0" max="255" value={this.state.b}  onChange={this.saveB}/><br/>
                    </div>
                </div>
            }

            saveR = (e) => {
                this.setState({
                    r: e.target.value
                })
            }

            saveG = (e) => {
                this.setState({
                    g: e.target.value
                })
            }

            saveB = (e) => {
                this.setState({
                    b: e.target.value
                })
            }

        }

        ReactDOM.render(<App />, document.querySelector("#root"));
    </script>
</body>
</html>